<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>作品管理</title>


    <!-- Expand styles -->
    <link href="../css/app/app.css" rel="stylesheet">
    <link href="../css/app/default.css" rel="stylesheet">
    <link href="../css/mui/mui.css" rel="stylesheet">


    <!-- Custom styles for this template -->
    <!-- <link href="../css/iOS/mobile/mobile.css" rel="stylesheet"> -->
</head>

<body>
    <!-- header -->
    <div>
        <div class="widget-default margin-b-5">
            <div class="farming-tab-two">
                <div id="segmentedControl" class="mui-segmented-control">
                    <a class="mui-control-item mui-active" sourceType="AGRT_TECH_VIDEO">农技视频</a>
                    <a class="mui-control-item" sourceType="SMALL_VIDEO">小视频</a>
                </div>
            </div>
        </div>
    </div>
    <div id="pullrefresh" class="mui-content mui-scroll-wrapper  " style="margin-top: 55px;">
        <div class="mui-scroll">
            <!-- 关注 -->
            <div class="mui-control-content mui-active">
                <div id="expertListDiv">

                    <!-- 视频列表 -->
                    <div id="videoList">
                    </div>
                </div>
            </div>
        </div>

    </div>
    <script src="../js/dsbridge.js"></script>
    <script src="../js/jquery.js"></script>
    <script src="../js/mui/mui.js"></script>
    <script src="../js/mui/mui.picker.min.js"></script>
    <script src="../js/layer.js"></script>
    <script src="../js/app/app-base.js"></script>
    <script src="../js/app/app-url.js"></script>
    <script src="../js/app/app-ajax.js"></script>

    <script>

        var page = 1;
        var limit = 10;
        var index = 0;
        var all_data = new Array();
        //页面类型  
        var sourceType = 'my_publish';
        var type = 'AGRT_TECH_VIDEO';
        $(document).ready(function () {

            mui.init({
                pullRefresh: {
                    container: '#pullrefresh',
                    down: {
                        auto: true, // 首次进入自动加载
                        callback: pulldownRefresh
                    },
                    up: {
                        contentrefresh: '正在加载...',
                        callback: pullupRefresh
                    }
                }
            });

            dsBridge.register('refresh', function () {
 
                pulldownRefresh();
            })


        })

        //一级类型切换
        mui("#segmentedControl").on('tap', '.mui-control-item', function () {
            type = $(this).attr("sourceType");
            pulldownRefresh();
        });




        /**
         * 下拉刷新具体业务实现
         */
        function pulldownRefresh() {
            page = 1;
            var data = {
                sourceType: sourceType,
                userAccId: getUserId(),
                type: type,
                page: page,
                limit: limit
            }
            getServerData(url_agrivideoInfo_queryList, data);
        }

        /**
         * 上拉加载具体业务实现
         */
        function pullupRefresh() {
            page++;
            var data = {
                sourceType: sourceType,
                userAccId: getUserId(),
                type: type,
                page: page,
                limit: limit
            }
            getServerData(url_agrivideoInfo_queryList, data);
        }


        function getServerDataSuccess(url, data) {
            switch (url) {
                case url_agrivideoInfo_queryList:
                    var list = data.data;
                    if (page == 1) {
                        index = 0;
                        all_data.length = 0;
                    }
                    var h5 = '';
                    if (list != null && list.length > 0) {

                        $.each(list, function (index, item) {
                            all_data.push(item);
                            h5 += '<div class="widget-body widget-default margin-b-5"  id="' + index + '">' +
                                '<div class="margin-t-5 trade-list videoDetail" dId="' + index + '" >' +
                                '<img   width="100%" height="177"   src="' + showSmallImg(item.coverImg) + '" alt="">' +
                                '<p class=" elli1 black font-15 padding-t-15 padding-l-5 no-margin">' +
                                item.title + '</p>' +
                                '</div>' +
                                '<div class="display-flex justify-content-end align-items-center padding-t-6">' +
                                '<span class="gray font-12 padding-l-5">' + item.createTime + '</span>' +
                                '</div>' +
                                '<div class="display-flex justify-content-end padding-t-6">' +
                                '<span class="btn-delete font-13 margin-l-10 gray delete-btn">删除</span>';
                            if (item.auditStatus == 2) {
                                h5 += '<span class="btn-delete font-13 margin-l-10 gray auditOpinion" id="' + item.auditOpinion + '">驳回原因</span>';
                            }

                            h5 += '<span class="btn-delete font-13 margin-l-10 gray edit" id="' + item.id + '">编辑</span>' +
                                '</div>' +
                                '</div>';
                        })

                    }
                    if (page == 1) {
                        mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
                        if (list.length > 0) {
                            mui('#pullrefresh').pullRefresh().refresh(true);
                        }
                        $("#videoList").html(h5);
                    } else {
                        $("#videoList").append(h5);
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(list.length != limit);
                    }
                    break;
                case url_agrivideoInfo_delete:
                    pulldownRefresh();
                    layer.open({
                        content: '删除成功',
                        btn: ['确定'],
                        yes: function (index) {
                            layer.close(index);
                        }
                    });
                    break;

            }

        }


        function getServerDataFailed(url, data) {
            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
            mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
        }

        //详情
        mui(".mui-content").on('tap', '.videoDetail', function () {
            var detailIndex = $(this).attr("dId");
            console.log(all_data[detailIndex].id);
            if (all_data[detailIndex].type == 'AGRT_TECH_VIDEO') {
                //农技视频
                localStorage.setItem("video-detail-id", all_data[detailIndex].id);
                dsBridge.call("goAgriTechVideoDetail", "");
            } else if (all_data[detailIndex].type == 'SMALL_VIDEO') {
                //小视频
                dsBridge.call("smallVideo", all_data[detailIndex].id);
            }
        });



        //删除
        mui("#videoList").on('tap', '.delete-btn', function () {
            event.stopPropagation();
            var evalIndex = $(this).parents(".widget-body").attr("id");
            console.log(all_data[evalIndex].id);
            layer.open({
                content: '是否删除该条记录？',
                btn: ['删除', '取消'],
                yes: function (index) {
                    var data = {
                        id: all_data[evalIndex].id
                    }
                    getServerData(url_agrivideoInfo_delete, data, "POST");
                    layer.close(index);
                }
            });
        });
        //驳回原因
        mui("#videoList").on('tap', '.auditOpinion', function () {
            event.stopPropagation();
            showAlert($(this).attr("id"));
        });
        //编辑
        mui("#videoList").on('tap', '.edit', function () {
            event.stopPropagation();
            localStorage.setItem("video-id", this.id);
            localStorage.setItem("video-type", type);
            dsBridge.call("addVideo");
        });


    </script>

</body>

</html>